package com.ruoyi.web.controller.jiaxiao;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.JxSubject;
import com.ruoyi.system.domain.JxInstructorSubject;
import com.ruoyi.system.domain.JxInstructorStudent;
import com.ruoyi.system.service.IJxSubjectService;
import com.ruoyi.system.service.IJxAssignService;

/** 分配相关：科目与学员分配 */
@RestController
@RequestMapping("/jiaxiao/assign")
public class JxAssignController extends BaseController {

    @Autowired
    private IJxSubjectService subjectService;

    @Autowired
    private IJxAssignService assignService;

    @PreAuthorize("@ss.hasPermi('jiaxiao:assign:list')")
    @GetMapping("/subjects")
    public AjaxResult subjects(JxSubject query) {
        List<JxSubject> list = subjectService.selectJxSubjectList(query);
        return AjaxResult.success(list);
    }

    // 教练-科目
    @PreAuthorize("@ss.hasPermi('jiaxiao:assign:list')")
    @GetMapping("/instructor/subjects")
    public AjaxResult instructorSubjects(@RequestParam Long staffId) {
        List<JxInstructorSubject> list = assignService.listInstructorSubjects(staffId);
        return AjaxResult.success(list);
    }

    @PreAuthorize("@ss.hasPermi('jiaxiao:assign:edit')")
    @PostMapping("/instructor/subject")
    public AjaxResult addInstructorSubject(@RequestParam Long staffId, @RequestParam Long subjectId) {
        return toAjax(assignService.addInstructorSubject(staffId, subjectId));
    }

    @PreAuthorize("@ss.hasPermi('jiaxiao:assign:edit')")
    @DeleteMapping("/instructor/subject")
    public AjaxResult removeInstructorSubject(@RequestParam Long staffId, @RequestParam Long subjectId) {
        return toAjax(assignService.removeInstructorSubject(staffId, subjectId));
    }

    // 教练-学员
    @PreAuthorize("@ss.hasPermi('jiaxiao:assign:list')")
    @GetMapping("/instructor/students")
    public AjaxResult instructorStudents(@RequestParam Long staffId) {
        List<JxInstructorStudent> list = assignService.listInstructorStudents(staffId);
        return AjaxResult.success(list);
    }

    @PreAuthorize("@ss.hasPermi('jiaxiao:assign:list')")
    @GetMapping("/instructor/students/count")
    public AjaxResult instructorStudentsCount(@RequestParam Long staffId) {
        return AjaxResult.success(assignService.countInstructorStudents(staffId));
    }

    @PreAuthorize("@ss.hasPermi('jiaxiao:assign:edit')")
    @PostMapping("/instructor/student")
    public AjaxResult addInstructorStudent(@RequestParam Long staffId, @RequestParam Long studentId, @RequestParam(required = false) String remark) {
        return toAjax(assignService.addInstructorStudent(staffId, studentId, remark));
    }

    @PreAuthorize("@ss.hasPermi('jiaxiao:assign:edit')")
    @DeleteMapping("/instructor/student")
    public AjaxResult removeInstructorStudent(@RequestParam Long staffId, @RequestParam Long studentId) {
        return toAjax(assignService.removeInstructorStudent(staffId, studentId));
    }
}


